# -*- coding:utf-8 -*-
# @Time: 2020/7/15 10:30
# @Author: liupengfei
# @File: serializers.py

from rest_framework import serializers
from .models import Menu, PermissionGroup, Permission, Role
from .middlewares import rbac


class MenuSerializer(serializers.ModelSerializer):
    class Meta:
        model = Menu
        fields = '__all__'


class MenuDictSerializer(serializers.ModelSerializer):
    code = serializers.IntegerField(source='id', read_only=True)
    codeName = serializers.CharField(source='name', read_only=True)

    class Meta:
        model = Menu
        fields = ('code', 'codeName')


class PermissionGroupSerializer(serializers.ModelSerializer):
    # menu = serializers.CharField(source='menu.name', read_only=True)

    class Meta:
        model = PermissionGroup
        fields = '__all__'


class PermissionGroupDictSerializer(serializers.ModelSerializer):
    code = serializers.IntegerField(source='id', read_only=True)
    codeName = serializers.CharField(source='caption', read_only=True)

    class Meta:
        model = Menu
        fields = ('code', 'codeName')


class PermissionSerializer(serializers.ModelSerializer):
    class Meta:
        model = Permission
        fields = '__all__'


# class PermissionGroupDictSerializer(serializers.ModelSerializer):
#     code = serializers.IntegerField(source='id', read_only=True)
#     codeName = serializers.CharField(source='caption', read_only=True)
#
#     class Meta:
#         model = Menu
#         fields = ('code', 'codeName')


class RoleSerializer(serializers.ModelSerializer):
    class Meta:
        model = Role
        fields = '__all__'
